//
//  YDABaseTabBarController.m
//  siyanone
//
//  Created by LK-IOS on 2018/3/21.
//  Copyright © 2018年 LK-News. All rights reserved.
//

#import "YDABaseTabBarController.h"
#import "YDTabBar.h"

#import "YDAHomeController.h"
#import "YDANewsController.h"
#import "YDAOptionController.h"
#import "YDAMineController.h"

@interface YDABaseTabBarController ()

@end

@implementation YDABaseTabBarController

- (void)viewDidLoad
{
    [super viewDidLoad];
    //添加所有子控制器
    [self setUpAllChildsViewControllers];
    //设置tabbar上按钮的图片及文字
    [self setUpAllTabbarItemsTitle];
    [self setUpTab];
    
}

#pragma mark 替换系统的TabBar
-(void)setUpTab
{
    
    YDTabBar *tabBar = [[YDTabBar alloc] init];
    UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageWithColor:NumberColor(255, 255 , 255)]];
    
    img.frame = CGRectMake(0, 0, self.tabBar.frame.size.width, self.tabBar.frame.size.height + 34);
    img.contentMode = UIViewContentModeScaleToFill;
    [tabBar insertSubview:img atIndex:0];
    [self setValue:tabBar forKey:@"tabBar"];
}

#pragma mark 设置UITabBar上按钮的尺寸和字体
+(void)load
{
    //正常状态
    UITabBarItem *barItem = [UITabBarItem appearanceWhenContainedIn:self ,nil];
    NSMutableDictionary *norDict = [NSMutableDictionary dictionary];
    norDict[NSFontAttributeName] = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
    norDict[NSForegroundColorAttributeName] = NumberColor(178, 176, 179);;
    [barItem setTitleTextAttributes:norDict forState:UIControlStateNormal];
    
    //选中状态
    NSMutableDictionary *selDict = [NSMutableDictionary dictionary];
    selDict[NSFontAttributeName] = [UIFont systemFontOfSize:font12ScreenWRate * LKScreenW];
    selDict[NSForegroundColorAttributeName] = [UIColor blackColor];
    [barItem setTitleTextAttributes:selDict forState:UIControlStateSelected];
    
}

-(BOOL)canBecomeFirstResponder
{
    return YES;
}

#pragma mark 添加所有子控制器
-(void)setUpAllChildsViewControllers
{
    //首页
    YDAHomeController *vc1 = [[YDAHomeController alloc] init];
    YDABaseNavigationController *nav1 = [[YDABaseNavigationController alloc] initWithRootViewController:vc1];
    nav1.fullScreenPopGestureEnabled = YES;
    [self addChildViewController:nav1];
    
    //资讯
    YDANewsController *vc2 = [[YDANewsController alloc] init];
    YDABaseNavigationController *nav2 = [[YDABaseNavigationController alloc] initWithRootViewController:vc2];
    nav2.fullScreenPopGestureEnabled = YES;
    [self addChildViewController:nav2];
    
    //自选
    YDAOptionController *vc3 = [[YDAOptionController alloc] init];
    YDABaseNavigationController *nav3 = [[YDABaseNavigationController alloc] initWithRootViewController:vc3];
    nav3.fullScreenPopGestureEnabled = YES;
    [self addChildViewController:nav3];
    
    //我的
    YDAMineController *vc4 = [[YDAMineController alloc] init];
    YDABaseNavigationController *nav4 = [[YDABaseNavigationController alloc] initWithRootViewController:vc4];
    nav4.fullScreenPopGestureEnabled = YES;
    [self addChildViewController:nav4];
    
    
}
#pragma mark 设置tabbar上按钮的图片及文字
-(void)setUpAllTabbarItemsTitle
{
    //
    YDABaseNavigationController *nav0 = self.childViewControllers[0];
    nav0.tabBarItem.title = @"首页";
    nav0.tabBarItem.image = [UIImage imageWIthOriginalImage:@"yd_tab-shouye_nor"];
    nav0.tabBarItem.selectedImage = [UIImage imageWIthOriginalImage:@"yd_tab-shouye_sel"];
    
    //
    YDABaseNavigationController *nav1 = self.childViewControllers[1];
    nav1.tabBarItem.title = @"要闻";
    nav1.tabBarItem.image = [UIImage imageWIthOriginalImage:@"yd_tab-zixun_nor"];
    nav1.tabBarItem.selectedImage = [UIImage imageWIthOriginalImage:@"yd_tab-zixun_sel"];
    
    //
    YDABaseNavigationController *nav2 = self.childViewControllers[2];
    nav2.tabBarItem.title = @"自选";
    nav2.tabBarItem.image = [UIImage imageWIthOriginalImage:@"yd_tab-qiquan-nor"];
    nav2.tabBarItem.selectedImage = [UIImage imageWIthOriginalImage:@"yd_tab-qiquan-sel"];
    
    //
    YDABaseNavigationController *nav3 = self.childViewControllers[3];
    nav3.tabBarItem.title = @"我的";
    nav3.tabBarItem.image = [UIImage imageWIthOriginalImage:@"yd_tab_wode_nor"];
    nav3.tabBarItem.selectedImage = [UIImage imageWIthOriginalImage:@"yd_tab_wode_sel"];
    
}



@end
